package com.itheima.springboottilasmanager.controller;

import com.itheima.springboottilasmanager.pojo.domain.Clazz;
import com.itheima.springboottilasmanager.pojo.domain.PageResult;
import com.itheima.springboottilasmanager.pojo.domain.Result;
import com.itheima.springboottilasmanager.pojo.vo.queryString;
import com.itheima.springboottilasmanager.survice.ClazzSurvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("clazzs")
public class ClazzController {
    @Autowired
   private ClazzSurvice clazzSurvice;

    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){

        return clazzSurvice.addClazz(clazz)?Result.success(): Result.error("添加失败");
    }
    @GetMapping
    public Result findall(queryString qs){
        PageResult<Clazz> pageResult = clazzSurvice.findall(qs);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id){
        return clazzSurvice.deleteClazz(id)?Result.success(): Result.error("删除失败");
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        Clazz clazzList = clazzSurvice.selectById(id);
        return Result.success(clazzList);
    }
@PutMapping
//    public Result updateClazz(@RequestBody Clazz clazz){
//        clazzSurvice.updateClazz(clazz);
//    System.out.println("收到的对象：" + clazz);
//        return Result.success();
//    }
public Result updateClazzRaw(@RequestBody Clazz clazz){
   clazzSurvice.updateClazz(clazz);
    return Result.success();
}
@GetMapping("/list")
    public Result selectAll(){
    List<Clazz> clazzList = clazzSurvice.selectAll();
        return Result.success(clazzList);
    }
}
